import fitz  # type: ignore
from .utils import pixmap_to_image, compare_two_image


dir_path = "/home/huang/Documents/machine-readproofing/测试文件"
file1 = "国家普通话水平测试准考证1.pdf"
file2 = "国家普通话水平测试准考证2.pdf"
doc1 = fitz.open(dir_path + "/" + file1)
doc2 = fitz.open(dir_path + "/" + file2)
if len(doc1) != len(doc2):
    EncodingWarning("两个文件页面数不一样！")
for i in range(len(doc1)):
    image1 = pixmap_to_image(doc1[i].get_pixmap(dpi=360)).convert("L")
    image2 = pixmap_to_image(doc2[i].get_pixmap(dpi=360)).convert("L")
    # 确保两张图片尺寸相同
    similarity_score = compare_two_image(image1, image2)
    if similarity_score < 0.99:
        print("the page %d is Difference!" % i)
        EncodingWarning("请检查该不同点。")
    else:
        print(similarity_score)
print("OK!")
